    program merge_crsp_util_fee_rep
    character*6 tick(2900000),ticker
    character*8 cusip,cusp,tcusp
    character*9 price(76),temp9,retrn(76) 
    integer(kind=8) nshrs(76),nvalue(76),jvalue(76),ivol(76),numshrs(76)
    dimension jast(76),jdate(76),cusp(76),ticker(76),itickt(76),age(76),favg(76),fmax(76),fmin(76),fstd(76),iperm(76)
    dimension ishrout(76),vwret(76),util(76)
!      open(unit=11,file='e:\FIS\crsp_sorted_fees_200501_200503.txt')
!      open(unit=12,file='e:\FIS\crsp_sorted_fees_200504_200506.txt')
!      open(unit=13,file='e:\FIS\crsp_sorted_fees_200507_200509.txt')
!      open(unit=14,file='e:\FIS\crsp_sorted_fees_200510_200512.txt')
!      open(unit=15,file='e:\FIS\crsp_sorted_fees_200601_200603.txt')
!      open(unit=16,file='e:\FIS\crsp_sorted_fees_200604_200606.txt')
!      open(unit=17,file='e:\FIS\crsp_sorted_fees_200607_200609.txt')
!      open(unit=18,file='e:\FIS\crsp_sorted_fees_200610_200612.txt')
!      open(unit=19,file='e:\FIS\crsp_util_sorted_fees_200701_200703.txt')
!      open(unit=20,file='e:\FIS\crsp_util_sorted_fees_200704_200706.txt')
!      open(unit=21,file='e:\FIS\crsp_util_sorted_fees_200707_200709.txt')
!      open(unit=22,file='e:\FIS\crsp_util_sorted_fees_200710_200712.txt')
!      open(unit=23,file='e:\FIS\crsp_util_sorted_fees_200801_200803.txt')
!      open(unit=24,file='e:\FIS\crsp_util_sorted_fees_200804_200806.txt')
!      open(unit=25,file='e:\FIS\crsp_util_sorted_fees_200807_200809.txt')
!      open(unit=26,file='e:\FIS\crsp_util_sorted_fees_200810_200812.txt')
!      open(unit=27,file='e:\FIS\crsp_util_sorted_fees_200901_200903.txt')
!      open(unit=28,file='e:\FIS\crsp_util_sorted_fees_200904_200906.txt')
!      open(unit=29,file='e:\FIS\crsp_util_sorted_fees_200907_200909.txt')
!      open(unit=30,file='e:\FIS\crsp_util_sorted_fees_200910_200912.txt')
!      open(unit=31,file='e:\FIS\crsp_util_sorted_fees_201001_201003.txt')
!      open(unit=32,file='e:\FIS\crsp_util_sorted_fees_201004_201006.txt')
!      open(unit=33,file='e:\FIS\crsp_util_sorted_fees_201007_201009.txt')
!      open(unit=34,file='e:\FIS\crsp_util_sorted_fees_201010_201012.txt')
!      open(unit=35,file='e:\FIS\crsp_util_sorted_fees_201101_201103.txt')
!      open(unit=36,file='e:\FIS\crsp_util_sorted_fees_201104_201106.txt')
!      open(unit=37,file='e:\FIS\crsp_util_sorted_fees_201107_201109.txt')
!      open(unit=38,file='e:\FIS\crsp_util_sorted_fees_201110_201112.txt')
!      open(unit=39,file='e:\FIS\crsp_util_sorted_fees_201201_201203.txt')
!      open(unit=40,file='e:\FIS\crsp_util_sorted_fees_201204_201206.txt')
!      open(unit=41,file='e:\FIS\crsp_util_sorted_fees_201207_201209.txt')
!      open(unit=42,file='e:\FIS\crsp_util_sorted_fees_201210_201212.txt')
!      open(unit=43,file='e:\FIS\crsp_util_sorted_fees_201301_201303.txt')
!      open(unit=44,file='e:\FIS\crsp_util_sorted_fees_201304_201306.txt')
!      open(unit=45,file='e:\FIS\crsp_util_sorted_fees_201307_201309.txt')
!      open(unit=46,file='e:\FIS\crsp_util_sorted_fees_201310_201312.txt')
!      open(unit=47,file='e:\FIS\crsp_util_sorted_fees_201401_201403.txt')
!      open(unit=48,file='e:\FIS\crsp_util_sorted_fees_201404_201406.txt')
!      open(unit=49,file='e:\FIS\crsp_util_sorted_fees_201407_201409.txt')
!      open(unit=50,file='e:\FIS\crsp_util_sorted_fees_201410_201412.txt')
!      open(unit=51,file='e:\FIS\crsp_util_sorted_fees_201501_201503.txt')
!      open(unit=52,file='e:\FIS\crsp_util_sorted_fees_201504_201506.txt')
!      open(unit=53,file='e:\FIS\crsp_util_sorted_fees_201507_201509.txt')
!      open(unit=54,file='e:\FIS\crsp_util_sorted_fees_201510_201512.txt')
!      open(unit=55,file='e:\FIS\crsp_util_sorted_fees_201601_201603.txt')
!      open(unit=56,file='e:\FIS\crsp_util_sorted_fees_201604_201606.txt')
!      open(unit=57,file='e:\FIS\crsp_util_sorted_fees_201607_201609.txt')
!      open(unit=58,file='e:\FIS\crsp_util_sorted_fees_201610_201612.txt')
!      open(unit=59,file='e:\FIS\crsp_util_sorted_fees_201701_201703.txt')
!      open(unit=60,file='e:\FIS\crsp_util_sorted_fees_201704_201706.txt')
!      open(unit=61,file='e:\FIS\crsp_util_sorted_fees_201707_201709.txt')
!      open(unit=62,file='e:\FIS\crsp_util_sorted_fees_201710_201712.txt')
!      open(unit=63,file='e:\FIS\crsp_util_sorted_fees_201801_201803.txt')
!      open(unit=64,file='e:\FIS\crsp_util_sorted_fees_201804_201806.txt')
!      open(unit=65,file='e:\FIS\crsp_util_sorted_fees_201807_201809.txt')
!      open(unit=66,file='e:\FIS\crsp_util_sorted_fees_201810_201812.txt')
!      open(unit=67,file='e:\FIS\crsp_util_sorted_fees_201901_201903.txt')
!      open(unit=68,file='e:\FIS\crsp_util_sorted_fees_201904_201906.txt')
!      open(unit=69,file='e:\FIS\crsp_util_sorted_fees_201907_201909.txt')
!      open(unit=70,file='e:\FIS\crsp_util_sorted_fees_201910_201912.txt')
!      open(unit=71,file='e:\FIS\crsp_util_sorted_fees_202001_202003.txt')
!      open(unit=72,file='e:\FIS\crsp_util_sorted_fees_202004_202006.txt')
!      open(unit=73,file='e:\FIS\crsp_util_sorted_fees_202007_202009.txt')
!      open(unit=74,file='e:\FIS\crsp_util_sorted_fees_202010_202012.txt')
!      open(unit=75,file='e:\FIS\crsp_util_sorted_fees_202101_202103.txt')
!      open(unit=76,file='e:\FIS\crsp_util_sorted_fees_202104_202106.txt')
!      open(unit=77,file='e:\FIS\crsp_util_sorted_fees_202107_202109.txt')
!      open(unit=78,file='e:\FIS\crsp_util_sorted_fees_202110_202112.txt')
!      open(unit=79,file='e:\FIS\crsp_util_sorted_fees_202201_202203.txt')
!      open(unit=80,file='e:\FIS\crsp_util_sorted_fees_202204_202206.txt')
!      open(unit=81,file='e:\FIS\crsp_util_sorted_fees_202207_202209.txt')
!      open(unit=82,file='e:\FIS\crsp_util_sorted_fees_202210_202212.txt')
!      open(unit=83,file='e:\FIS\crsp_util_sorted_fees_202301_202303.txt')
!      open(unit=84,file='e:\FIS\crsp_util_sorted_fees_202304_202306.txt')
!      open(unit=85,file='e:\FIS\crsp_util_sorted_fees_202307_202309.txt')
!      open(unit=86,file='e:\FIS\crsp_util_sorted_fees_202310_202312.txt')
      open(unit=11,file='e:\FIS\crsp_util_sorted_fees_200701_200703_rep.txt')
      open(unit=12,file='e:\FIS\crsp_util_sorted_fees_201401_201403_rep.txt')
      open(unit=99,file='e:\FIS\crsp_util_sorted_fees_2005_2023_rep.txt')
      min=99999999
!      do 10 ifl=11,86
      do 10 ifl=11,12
          i=ifl-10
!          if(ifl.gt.18) go to 3
          if(ifl.gt.10) go to 3
      read(ifl,1100)jast(i),jdate(i),cusp(i),ticker(i),itickt(i),numshrs(i),jvalue(i),age(i),favg(i),fmax(i),fmin(i),fstd(i),iperm(i),idate2,tcusp,price(i),ivol(i),retrn(i),ishrout(i),vwret(i)      
1100  format(2(1x,i8),1x,a8,2x,a6,4x,i9,2(1x,i14),5(1x,f11.4),1x,i5,1x,i8,1x,a8,1x,a9,1x,i10,1x,a9,1x,i9,1x,f9.6)  
      temp9=retrn(i)
      ik=0
      do 2 k=1,9
2     if(temp9(k:k).eq.'B'.or.temp9(k:k).eq.'C') ik=1
      if(ik.eq.1) retrn(i)='-9.999999'
      util(i)=-9.99
      nshrs(i)=-9
      nvalue(i)=-9
      go to 5
3     read(ifl,1000)jast(i),jdate(i),cusp(i),ticker(i),itickt(i),numshrs(i),jvalue(i),age(i),favg(i),fmax(i),fmin(i),fstd(i),iperm(i),price(i),ivol(i),retrn(i),ishrout(i),vwret(i),iastid,idate,cusip,util(i),nshrs(i),nvalue(i)      
1000  format(2(1x,i8),1x,a8,2x,a6,4x,i9,2(1x,i14),5(1x,f11.4),1x,i5,1x,a9,1x,i10,1x,a9,1x,i9,1x,f9.6,2(1x,i8),1x,a9,1x,f6.2,2(1x,i13))   
5     if(jast(i).lt.min) min=jast(i)
      temp9=retrn(i)
      ik=0
      do 7 k=1,9
7     if(temp9(k:k).eq.'B'.or.temp9(k:k).eq.'C') ik=1
      if(ik.eq.1) retrn(i)='-9.999999'
!      write(6,1001)jast(i),jdate(i),cusp(i),ticker(i),itickt(i),numshrs(i),jvalue(i),age(i),favg(i),fmax(i),fmin(i),fstd(i),iperm(i),price(i),ivol(i),retrn(i),ishrout(i),vwret(i),util(i),nshrs(i),nvalue(i)      
1001  format(2(1x,i8),1x,a8,2x,a6,4x,i9,2(1x,i14),5(1x,f11.4),1x,i5,1x,a9,1x,i10,1x,a9,1x,i9,1x,f9.6,1x,f6.2,2(1x,i13))   
10    continue      
15    continue      
!      do 50 ifl=11,86
      do 50 ifl=11,12
      i=ifl-10
20    if(jast(i).ne.min) go to 50
!      write(6,1001)jast(i),jdate(i),cusp(i),ticker(i),itickt(i),numshrs(i),jvalue(i),age(i),favg(i),fmax(i),fmin(i),fstd(i),iperm(i),price(i),ivol(i),retrn(i),ishrout(i),vwret(i),util(i),nshrs(i),nvalue(i)      
      temp9=price(i)
      ic=0
      do 22 k=1,9
22    if(temp9(k:k).eq.',') ic=k
      if(ic.eq.0) go to 28
      do 25 k=ic,2,-1
          km=k-1
25    temp9(k:k)=temp9(km:km)
      temp9(1:1)=' '
      price(i)=temp9
28    write(99,1001)jast(i),jdate(i),cusp(i),ticker(i),itickt(i),numshrs(i),jvalue(i),age(i),favg(i),fmax(i),fmin(i),fstd(i),iperm(i),price(i),ivol(i),retrn(i),ishrout(i),vwret(i),util(i),nshrs(i),nvalue(i)      
      if(ifl.gt.10) go to 30
      read(ifl,1100,end=40)jast(i),jdate(i),cusp(i),ticker(i),itickt(i),numshrs(i),jvalue(i),age(i),favg(i),fmax(i),fmin(i),fstd(i),iperm(i),idate2,tcusp,price(i),ivol(i),retrn(i),ishrout(i),vwret(i)      
      temp9=retrn(i)
      ik=0
      do 29 k=1,9
29    if(temp9(k:k).eq.'B'.or.temp9(k:k).eq.'C') ik=1
      if(ik.eq.1) retrn(i)='-9.999999'
      util(i)=-9.99
      nshrs(i)=-9
      nvalue(i)=-9
      go to 20
30    read(ifl,1000,end=40)jast(i),jdate(i),cusp(i),ticker(i),itickt(i),numshrs(i),jvalue(i),age(i),favg(i),fmax(i),fmin(i),fstd(i),iperm(i),price(i),ivol(i),retrn(i),ishrout(i),vwret(i),iastid,idate,cusip,util(i),nshrs(i),nvalue(i)      
      temp9=retrn(i)
      ik=0
      do 32 k=1,9
32    if(temp9(k:k).eq.'B'.or.temp9(k:k).eq.'C') ik=1
      if(ik.eq.1) retrn(i)='-9.999999'
      go to 20
40    jast(i)=99999999      
50    continue 
      min=99999999
!      do 60 i=1,76
      do 60 i=1,2
60    if(jast(i).lt.min) min=jast(i) 
      write(6,6000)min
6000  format(1x,'minimum=',i9)   
      if(min.lt.90000000) go to 15
      stop

    end program merge_crsp_util_fee_rep
